<?php
require_once("gameObjects/user.php");
require_once("gameObjects/robot.php");
require_once("gameObjects/mainWeapon.php");
require_once("gameObjects/secWeapon.php");
require_once("gameObjects/storeHouse.php");

class userServer
{  
	/**
	 * 注册新用户
	 * @param mixed $userName 用户名
	 * @param mixed $password 密码
	 * @return mixed 成功返回uid,失败返回-1
	 *
	 */	
	public function regist($userName,$password)
	{
		$uid = user::generateUser($userName,$password);
		
		if($uid>0)
		{
			//给新注册的玩家新手装备
			robot::giveToUser($uid,1,0);
			mainWeapon::giveToUser($uid,1,0);
			secWeapon::giveToUser($uid,1,0);
			
			//给予新手第一个任务
			mission::addMission($uid,1,1);
			
			//将新手装备设置为已装备
			$sh = new storeHouse($uid);
			$sh->equipRobot(0);
			
			return $uid;
		}else return -1;
	}
	/**
	 * 用户登陆
	 * @param mixed $userName 用户名
	 * @param mixed $password 密码
	 * @return mixed 成功返回uid,失败返回-1
	 */    
    public function login($userName,$password)
    {
		return user::login($userName,$password);
    }
	
	public function getUser($uid)
	{
		$user = new user($uid);
		$data = array(
			"uname"=>$user->uname,
			"niname"=>$user->niname,
			"vip"=>$user->vip,
			"level"=>$user->level,
			"exp"=>$user->exp,
			"title"=>$user->title,
			"money"=>$user->money,
			"avi"=>$user->avi,
			"acc"=>$user->acc,
			"crit"=>$user->crit
		);
		
		return $data;
	}
	
	public function updatePeerID($uid,$peerID)
	{
		user::updatePeerID($uid,$peerID);
		
		return 1;
	}
	
	public function getPeerID($uid)
	{
		return user::getPeerID($uid);
	}
    
}


?>
